<template>
	<view class="container">
		<view class="header">
			<u-search :showAction="showAction" placeholder="请输入BOM名称" v-model="queryParams.name" @search="handleSearch"></u-search>
		</view>
		<view class="content">
			<scroll-view :scroll-top="scrollTop" scroll-y="true" class="scroll-Y" @scrolltoupper="upper"
				@scrolltolower="lower" @scroll="scroll" @refresherrefresh="onRefresh" refresher-enabled="true" :refresher-triggered="triggered">
				<view v-if="list.length>0"  class="scroll-view-item" v-for="(item,index) in list" :key="index">
					<view class="items">
						<view style="display: flex;align-items: center;">
							<view class="name">{{item.name}}</view>
							<view class="name-right">（{{item.bomCode}}）</view>
						</view>
						<view style="color: blue;margin-right: 20rpx;" @click="handleSubmit(item,index)">确定</view>
					</view>
				</view>
				<view v-if="list.length==0" class="None">
					暂无信息
				</view>
			</scroll-view>
		</view>
	</view>
</template>

<script>
	import {
		getBom
	} from '@/api/store.js'
	export default {
		data() {
			return {
				triggered:false,
				showAction:false,
				keyword:'',
				scrollTop:0,
				queryParams: {
					pageNo: 1, //页码
					pageSize: 20, //条数
					status: 20,
					name:''
				},
				list: [], //列表数据
				total: 0, //总条数
			}
		},
		onLoad() {
			this.getList()
		},
		methods: {
			// 获取BOM单列表
			async getList() {
				let res = await getBom(this.queryParams)
				this.list = [...this.list,...res.data.list]
				this.total = res.data.total
				setTimeout(()=>{
					this.triggered = false
				},500)
			},
			// 搜索
			async handleSearch(){
				this.queryParams.pageNo=1
				let res = await getBom(this.queryParams)
				this.list = res.data.list
				this.total = res.data.total
			},
			// 确定
			handleSubmit(item,index){
				console.log('item:',item);
				
				uni.$emit('bom', { data:item});
				uni.navigateBack()
			},
			upper(){},
			// 下拉刷新
			onRefresh(){
				this.triggered = true
				this.queryParams.pageNo=1
				this.list=[]
				this.getList()
			},
			// 上拉加载
			lower(){
				if(this.list.length<this.total){
					this.queryParams.pageNo++
					this.getList()
				}
			},
			scroll(){}
		}
	}
</script>

<style scoped>
	.name-right{
		width: 250rpx;
		height: 40rpx;
		 text-overflow: ellipsis;
		    overflow: hidden;
		    word-break: break-all;
		    white-space: nowrap;
	}
	.name{
		width: 300rpx;
		 text-overflow: ellipsis;
		    overflow: hidden;
		    word-break: break-all;
		    white-space: nowrap;
	}
	.None{
		width: 100%;
		height: 150rpx;
		font-size: 26rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		color: #999;
	}
	.items{
		width: 100%;
		height: 100rpx;
		display: flex;
		align-items: center;
		border-bottom: 1rpx solid #EBEBEB;
		font-size: 26rpx;
		justify-content: space-between;
	}
	.header{
		width: 100%;
		padding: 30rpx;
		box-sizing: border-box;
		height: 100rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		background-color: #FFFFFF;
		margin-bottom: 15rpx;
		margin-top: 15rpx;
	}
	.content{
		width: 720rpx;
		height: 100vh;
		background-color: #FFFFFF;
		border-radius: 5rpx;
		padding: 10rpx;
		box-sizing: border-box;
	}
	.scroll-Y{
		width: 690rpx;
		height: calc(100vh - 200rpx);
	}
	.container{
		width: 750rpx;
		height: 100vh;
		display: flex;
		flex-direction: column;
		align-items: center;
		background-color: #F8F8F8;
	}
</style>